<?php

namespace zhtfrontend\models\datas;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\helpers\ArrayHelper;

/**
 * This is the model class for table "{{%class_manage_attribute}}".
 *
 * @property integer $id
 * @property integer $class_id
 * @property integer $coures_id
 * @property string $coures_name
 * @property integer $teacher_id
 * @property string $teacher
 * @property integer $room_id
 * @property string $classroom_name
 * @property string $classroom_number
 * @property integer $teache_form
 * @property string $price
 * @property integer $class_count
 * @property string $subsidy
 * @property string $suitable_age
 * @property integer $class_length
 * @property integer $max_number
 * @property integer $opening_number
 * @property integer $is_booking
 * @property string $region
 * @property integer $tutor_id
 * @property string $deposit
 * @property integer $is_group
 * @property integer $discount_type
 * @property integer $reduce
 * @property integer $subsidy_type
 * @property integer $commission_rate
 * @property integer $is_goods
 * @property integer $arrangement_id
 * @property integer $created_at
 * @property integer $room_type
 * @property integer $room_group_id
 */
class ClassManageAttribute extends \zhtfrontend\components\bases\BaseModel
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%class_manage_attribute}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['class_id', 'course_id', 'teacher_id', 'room_id', 'teacher_form', 'class_count', 'class_length', 'max_number', 'opening_number', 'is_booking','is_buy', 'tutor_id', 'is_group', 'discount_type', 'reduce', 'subsidy_type', 'commission_rate', 'is_goods', 'arrangement_id', 'created_at','updated_at','room_type','room_group_id','class_hour'], 'integer'],
            [['price', 'subsidy', 'deposit'], 'number'],
            [['course'], 'string', 'max' => 200],
            [['teacher', 'classroom_name', 'classroom_number', 'suitable_age','age_group','room_group_name'], 'string', 'max' => 50],
            [['region'], 'string', 'max' => 100],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('zhtfrontend', '自增id'),
            'class_id' => Yii::t('zhtfrontend', '班级id'),
            'course_id' => Yii::t('zhtfrontend', '课程id'),
            'course' => Yii::t('zhtfrontend', '课程名称'),
            'teacher_id' => Yii::t('zhtfrontend', '老师id'),
            'teacher' => Yii::t('zhtfrontend', '老师'),
            'room_id' => Yii::t('zhtfrontend', '教室id'),
            'classroom_name' => Yii::t('zhtfrontend', '教室'),
            'classroom_number' => Yii::t('zhtfrontend', '教室编号'),
            'teacher_form' => Yii::t('zhtfrontend', '授课方式'),
            'price' => Yii::t('zhtfrontend', '价格'),
            'class_count' => Yii::t('zhtfrontend', '课次'),
            'subsidy' => Yii::t('zhtfrontend', '课时补贴'),
            'suitable_age' => Yii::t('zhtfrontend', '年龄段'),
            'age_group' => Yii::t('zhtfrontend', '年龄组'),
            'class_length' => Yii::t('zhtfrontend', '时长'),
            'max_number' => Yii::t('zhtfrontend', '最满人数'),
            'opening_number' => Yii::t('zhtfrontend', '开班人数'),
            'is_booking' => Yii::t('zhtfrontend', '是否可预约'),
            'is_buy' => Yii::t('zhtfrontend', '是否可购买'),
            'region' => Yii::t('zhtfrontend', '区域'),
            'tutor_id' => Yii::t('zhtfrontend', '导师'),
            'deposit' => Yii::t('zhtfrontend', '保证金'),
            'is_group' => Yii::t('zhtfrontend', '是否组合艺教学 0 否 1是'),
            'discount_type' => Yii::t('zhtfrontend', '价格优惠类型（1，按比例 2 固定减额）'),
            'reduce' => Yii::t('zhtfrontend', '价格减少（比例整数）'),
            'subsidy_type' => Yii::t('zhtfrontend', '课时补助类型（1，按学生 2 课程）'),
            'commission_rate' => Yii::t('zhtfrontend', '佣金比例'),
            'is_goods' => Yii::t('zhtfrontend', '是否生成商品 0 否 1 是'),
            'arrangement_id' => Yii::t('zhtfrontend', '排课id'),
            'room_type' => Yii::t('zhtfrontend', '教室类型'),
            'room_group_id' => Yii::t('zhtfrontend', '共享教室组id'),
            'room_group_name' => Yii::t('zhtfrontend', '共享教室组'),
            'class_hour' => Yii::t('zhtfrontend', '课时数'),
            'updated_at' => Yii::t('zhtfrontend', '编辑时间'),
            'created_at' => Yii::t('zhtfrontend', '创建时间'),
        ];
    }

    public function getCourses(){
        return $this->hasOne(Course::className(),['id'=>'course_id']);
    }

    public function getTeachers(){
        return $this->hasOne(Teacher::className(),['id'=>'teacher_id']);
    }

    public function getClassroom(){
        return $this->hasOne(Classroom::className(),['id'=>'room_id']);
    }

    public function getCLassmanage(){
        return $this->hasOne(ClassManage::className(),['class_id'=>'class_id'])->where(['status'=>1]);
    }

    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            [
                'class' => TimestampBehavior::className(),
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
                    //ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
                ],
            ],
        ]);
    }
}
